﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class TreeNode
{
    private int value;
    private List<TreeNode> children;

    public TreeNode(int value)
    {
        this.value = value;
        this.children = new List<TreeNode>();
    }

    public int Value
    {
        get { return this.value; }
        set { this.value = value; }
    }

    public int ChildrenCount
    {
        get { return children.Count; }
    }

    public void AddChild(TreeNode child)
    {
        this.children.Add(child);
    }

    public TreeNode GetChild(int index)
    {
        return this.children[index];
    }
}

public class Tree
{
    private TreeNode root;

    public Tree(int value)
    {
        this.root = new TreeNode(value);
    }

    public Tree(int value, params Tree[] children)
        : this(value)
    {
        foreach (Tree child in children)
        {
            this.root.AddChild(child.root);
        }
    }

    public TreeNode Root
    {
        get { return this.root; }
        set { this.root = value; }
    }

    public int FindEncounters(int number)
    {
        return DFSTraverse(number, 0, root);
    }

    private int DFSTraverse(int number, int count, TreeNode node)
    {
        if (node.Value == number)
        {
            count++;
        }

        for (int i = 0; i < node.ChildrenCount; i++)
        {
            count = DFSTraverse(number, count, node.GetChild(i));
        }
        return count;
    }
}


class Program
{
    static void Main(string[] args)
    {
        string input = Console.ReadLine();
        int number = int.Parse(input);

        input = Console.ReadLine();
        Tree tree = ReadTree(input);

        Console.WriteLine(tree.FindEncounters(number));
    }

    static Tree ReadTree(string input)
    {
        string substring = input.Substring(1, input.Length - 2);
        int index = 0;
        StringBuilder sb = new StringBuilder();
        while (char.IsDigit(substring[index]))
        {
            sb.Append(substring[index]);
            index++;
        }
        Tree tree = new Tree(int.Parse(sb.ToString()));
        substring = substring.TrimStart("0123456789".ToCharArray());
        substring = substring.TrimStart("->".ToCharArray());

        List<string> branches = SplitBranches(substring);

        int leaf;
        foreach (var branch in branches)
        {
            if (int.TryParse(branch, out leaf))
            {
                tree.Root.AddChild(new TreeNode(leaf));
            }
            else
	        {
                tree.Root.AddChild(ReadTree(branch).Root);
	        }
        }
        return tree;
    }

    static List<string> SplitBranches(string input)
    {
        List<string> split = new List<string>();
        int count = 0;
        StringBuilder sb = new StringBuilder();
        foreach (var ch in input)
        {
            if (ch == ',' && count == 0)
            {
                split.Add(sb.ToString());
                sb.Clear();
                continue;
            }
            sb.Append(ch);
            if (ch == '(')
            {
                count++;
            }
            if (ch == ')')
            {
                count--;
            }
        }
        split.Add(sb.ToString());
        return split;
    }
}
